package br.com.webhomesites.padrao.presenter;

import br.com.webhomesites.padrao.model.FornecedorDAO;
import br.com.webhomesites.padrao.view.BuscarFornecedorView;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;

public class BuscarFornecedorPresenterActionListeners {
    
    static class BuscarFocusListener implements FocusListener {
        
        private BuscarFornecedorPresenter presenter;
        private BuscarFornecedorView buscarFornecedorView;
        
        public BuscarFocusListener(BuscarFornecedorPresenter presenter) {
            this.presenter = presenter;
            buscarFornecedorView = presenter.getBuscarFornecedorView();
        }
        
        @Override
        public void focusGained(FocusEvent e) {
            FornecedorDAO clienteDAO = new FornecedorDAO();
            if (e.getSource() == presenter.getBuscarFornecedorView().getComboCodigoJCombo()) {
                
                if (presenter.getBuscador() == presenter.BUSCADOR_LOCACAO_VIEW) {
                    System.out.println("Verdadeiro");
                    //buscarFornecedorView.setListaCodigo(clienteDAO.findByTipo("L"));
                } else {
                    System.out.println("Falso");
                    buscarFornecedorView.setListaCodigo(clienteDAO.findAll());
                    buscarFornecedorView.setListaNome(clienteDAO.findAll());
                    buscarFornecedorView.setListaCpf(clienteDAO.findAll());
                    buscarFornecedorView.setListaRg(clienteDAO.findAll());
                    buscarFornecedorView.setListaCnpj(clienteDAO.findAll());
                    buscarFornecedorView.setListaInscricaoEstadual(clienteDAO.findAll());
                }
                
                //buscarFornecedorView.comboDescricaoRemoveAllItens();
                //buscarFornecedorView.comboSerieRemoveAllItens();
                
                presenter.setTipoBusca(presenter.POR_CODIGO_STRATEGY);
                
            } else if (e.getSource() == presenter.getBuscarFornecedorView().getComboNomeJCombo()) {
                
                if (presenter.getBuscador() == presenter.BUSCADOR_LOCACAO_VIEW) {
                    //buscarFornecedorView.setListaDescricao(clienteDAO.findByTipo("C"));
                } else {
                    //buscarFornecedorView.setLista(clienteDAO.findAll());
                }
                
                //buscarFornecedorView.comboCodigoRemoveAllItens();
                //buscarFornecedorView.comboSerieRemoveAllItens();
                
                presenter.setTipoBusca(presenter.POR_NOME_STRATEGY);
                
            } else if (e.getSource() == presenter.getBuscarFornecedorView().getComboCpfJCombo()) {
                
                if (presenter.getBuscador() == presenter.BUSCADOR_LOCACAO_VIEW) {
                    //buscarFornecedorView.setListaSerie(clienteDAO.findByTipo("C"));
                } else {
                    //buscarFornecedorView.setListaSerie(clienteDAO.findAll());
                }
                
                //buscarFornecedorView.comboCodigoRemoveAllItens();
                //buscarFornecedorView.comboDescricaoRemoveAllItens();
                
                presenter.setTipoBusca(presenter.POR_CPF_STRATEGY);
                
            }
            
            else if (e.getSource() == presenter.getBuscarFornecedorView().getComboRgJCombo()) {
                
                if (presenter.getBuscador() == presenter.BUSCADOR_LOCACAO_VIEW) {
                    //buscarFornecedorView.setListaSerie(clienteDAO.findByTipo("C"));
                } else {
                    //buscarFornecedorView.setListaSerie(clienteDAO.findAll());
                }
                
                //buscarFornecedorView.comboCodigoRemoveAllItens();
                //buscarFornecedorView.comboDescricaoRemoveAllItens();
                
                presenter.setTipoBusca(presenter.POR_RG_STRATEGY);
                
            }
            
            else if (e.getSource() == presenter.getBuscarFornecedorView().getComboCnpjJCombo()) {
                
                if (presenter.getBuscador() == presenter.BUSCADOR_LOCACAO_VIEW) {
                    //buscarFornecedorView.setListaSerie(clienteDAO.findByTipo("C"));
                } else {
                    //buscarFornecedorView.setListaSerie(clienteDAO.findAll());
                }
                
                //buscarFornecedorView.comboCodigoRemoveAllItens();
                //buscarFornecedorView.comboDescricaoRemoveAllItens();
                
                presenter.setTipoBusca(presenter.POR_CNPJ_STRATEGY);
                
            }
            
            else if (e.getSource() == presenter.getBuscarFornecedorView().getComboInscricaoEstadualJCombo()) {
                
                if (presenter.getBuscador() == presenter.BUSCADOR_LOCACAO_VIEW) {
                    //buscarFornecedorView.setListaSerie(clienteDAO.findByTipo("C"));
                } else {
                    //buscarFornecedorView.setListaSerie(clienteDAO.findAll());
                }
                
                //buscarFornecedorView.comboCodigoRemoveAllItens();
                //buscarFornecedorView.comboDescricaoRemoveAllItens();
                
                presenter.setTipoBusca(presenter.POR_INSCRICAOESTADUAL_STRATEGY);
                
            }
            
        }
        
        @Override
        public void focusLost(FocusEvent e) {
            if (e.getSource() == presenter.getBuscarFornecedorView().getComboCodigoJCombo()) {
                
                //buscarFornecedorView.comboDescricaoRemoveAllItens();
                //buscarFornecedorView.comboSerieRemoveAllItens();
                
            } else if (e.getSource() == presenter.getBuscarFornecedorView().getComboNomeJCombo()) {
                
                //buscarFornecedorView.comboCodigoRemoveAllItens();
                //buscarFornecedorView.comboSerieRemoveAllItens();
                
            } else if (e.getSource() == presenter.getBuscarFornecedorView().getComboCpfJCombo()) {
                
                //buscarFornecedorView.comboCodigoRemoveAllItens();
                //buscarFornecedorView.comboDescricaoRemoveAllItens();
                
            }
        }
    }
    
    static class BuscarActionListener implements ActionListener {
        
        private BuscarFornecedorPresenter presenter;
        
        public BuscarActionListener(BuscarFornecedorPresenter presenter) {
            this.presenter = presenter;            
        }
        
        @Override
        public void actionPerformed(ActionEvent e) {
            presenter.getTipoBusca().execute();            
            presenter.getBuscarFornecedorView().dispose();
        }
    }
    
    static class SairActionListener implements ActionListener {
        
        @Override
        public void actionPerformed(ActionEvent evt) {
            System.exit(0);
        }
    }
}
